package com.jilefojing.beans.enums;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;

/**
 * 
 * @author 作者 jgshun
 * @date 创建时间 2016年07月19日 17时57分48秒
 */
public enum PlatformEnumForPublish {
	/**
	 * (short) 1, "所有平台"
	 */
	ALL((short) 1, "所有平台"),
	/**
	 * (short) 2, "web和wap "
	 */
	WEB_AND_WAP((short) 2, "web和wap "),
	/**
	 * (short) 3, "android和ios"
	 */
	ANDROID_AND_IOS((short) 3, "android和ios"),
	/**
	 * (short) 4, "web"
	 */
	WEB((short) 4, "web"),
	/**
	 * (short) 5, "wap"
	 */
	WAP((short) 5, "wap"),
	/**
	 * (short) 6, "android"
	 */
	ANDROID((short) 6, "android"),
	/**
	 * (short) 7, "ios"
	 */
	IOS((short) 7, "ios");

	private short code;
	private String msg;

	private PlatformEnumForPublish(short code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public short getCode() {
		return code;
	}

	public void setCode(short code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	@Override
	public String toString() {
		if (this != null) {
			Map<String, Object> allMap = new HashMap<String, Object>();
			allMap.put("code", this.code);
			allMap.put("msg", this.msg);
			String result = JSONObject.toJSONString(allMap);
			result = result.replaceAll("\"", "'");
			return result;
		}
		return super.toString();
	}

	public static PlatformEnumForPublish getPlatformEnumByCode(short code) {
		for (PlatformEnumForPublish _enum : PlatformEnumForPublish.values()) {
			if (_enum.getCode() == code) {
				return _enum;
			}
		}
		return null;
	}
}
